package com.sg.service.biz.pbff.impl;

import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.pbff.req.BffCommitHandRescueSlowTaskReqDto;
import com.sg.dto.biz.pbff.req.BffImplementAnalyseDogBoneResidueReqDto;
import com.sg.dto.biz.pbff.req.BffImplementEnableSpaceEverYoungDispatchMqReqDto;
import com.sg.dto.biz.pbff.res.BffCommitHandRescueSlowTaskRespDto;
import com.sg.dto.biz.pbff.res.BffImplementAnalyseDogBoneResidueRespDto;
import com.sg.dto.biz.pbff.res.BffImplementEnableSpaceEverYoungDispatchMqRespDto;
import com.sg.service.biz.pbff.TimingTaskService;
import com.wicket.okrapp.integration.*;
import com.wicket.okrapp.integration.dto.*;
import com.sg.common.exception.Assert;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class TimingTaskServiceImpl implements TimingTaskService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    com.sg.service.biz.app.DivineDataService fwAppDivineDataClient;

    @Resource
    com.sg.service.biz.app.TaskService fwAppTaskClient;

    @Resource
    com.sg.service.biz.app.TargetCycleService fwAppTargetCycleClient;

    @Resource
    com.sg.service.biz.app.TimingTaskService fwAppTimingTaskClient;

    @Resource
    com.sg.service.biz.app.TaskGenService fwAppTaskGenClient;
    @Resource
    com.sg.service.biz.app.IndexSystemService fwAppIndexSystemClient;
    @Resource
    com.sg.service.biz.app.EvaThemeService fwAppEvaThemeClient;

    /**
     * B3提交人工补偿异步调度任务(管理)(平台)[3300]
     * gen by moon at 5/3/2024, 11:49:00 PM
     */
    @Trace(operationName = "B3提交人工补偿异步调度任务(管理)(平台)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffCommitHandRescueSlowTaskRespDto commitHandRescueSlowTask(BffCommitHandRescueSlowTaskReqDto reqDto) {


        //virtualUsage D3执行定时任务接收参数  7058
        ImplementTimingTaskAcceptParametersRespDto implementTimingTaskAcceptParametersRespDto = null;
        ImplementTimingTaskAcceptParametersReqDto implementTimingTaskAcceptParametersReqDto = new ImplementTimingTaskAcceptParametersReqDto();
        if (reqDto != null) {
            implementTimingTaskAcceptParametersReqDto.setTimingTaskDispatchId(reqDto.getTimingTaskDispatchId());//SimpleFieldAssign//sourceId:142229_1_7058
            implementTimingTaskAcceptParametersReqDto.setDispatchActionTypeCode(reqDto.getDispatchActionTypeCode());//SimpleFieldAssign//sourceId:127544_1_7058
            implementTimingTaskAcceptParametersReqDto.setObjectTypeCode(reqDto.getObjectTypeCode());//SimpleFieldAssign//sourceId:142230_1_7058
            implementTimingTaskAcceptParametersReqDto.setStandbyField1(reqDto.getStandbyField1());//SimpleFieldAssign//sourceId:142231_1_7058
            implementTimingTaskAcceptParametersReqDto.setObjectId(reqDto.getObjectId());//SimpleFieldAssign//sourceId:127545_1_7058
            implementTimingTaskAcceptParametersReqDto.setAddRuleInfoTypeCode(reqDto.getAddRuleInfoTypeCode());//SimpleFieldAssign//sourceId:142232_1_7058
            implementTimingTaskAcceptParametersReqDto.setAddRuleInfoId(reqDto.getAddRuleInfoId());//SimpleFieldAssign//sourceId:127546_1_7058
            implementTimingTaskAcceptParametersReqDto.setAutoPlanTime(reqDto.getAutoPlanTime());//SimpleFieldAssign//sourceId:127547_1_7058
            implementTimingTaskAcceptParametersReqDto.setOperationInductionId(reqDto.getOperationInductionId());//SimpleFieldAssign//sourceId:142233_1_7058
            implementTimingTaskAcceptParametersReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:142234_1_7058
            implementTimingTaskAcceptParametersReqDto.setAppId(reqDto.getAppId());//SimpleFieldAssign//sourceId:252827_1_7058
        }

        /*D3执行定时任务接收参数[3303]   */
        Assert.isNull(implementTimingTaskAcceptParametersReqDto.getTimingTaskDispatchId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3执行定时任务接收参数-定时任务调度记录ID不能为空", false);
        Assert.isNull(implementTimingTaskAcceptParametersReqDto.getDispatchActionTypeCode(), "B3提交人工补偿异步调度任务(管理)(平台)-D3执行定时任务接收参数-任务调度的行为类型编码不能为空", false);
        Assert.isNull(implementTimingTaskAcceptParametersReqDto.getObjectTypeCode(), "B3提交人工补偿异步调度任务(管理)(平台)-D3执行定时任务接收参数-归属对象类型编码不能为空", false);
        Assert.isNull(implementTimingTaskAcceptParametersReqDto.getObjectId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3执行定时任务接收参数-归属对象内容ID不能为空", false);
        Assert.isNull(implementTimingTaskAcceptParametersReqDto.getOperationInductionId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3执行定时任务接收参数-操作人就职记录ID不能为空", false);
        Assert.isNull(implementTimingTaskAcceptParametersReqDto.getSpaceId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3执行定时任务接收参数-创建于空间ID不能为空", false);
        Assert.isNull(implementTimingTaskAcceptParametersReqDto.getAppId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3执行定时任务接收参数-创建于联盟应用ID不能为空", false);
        implementTimingTaskAcceptParametersRespDto = fwAppDivineDataClient.implementTimingTaskAcceptParameters(implementTimingTaskAcceptParametersReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


        if ((reqDto != null && reqDto.getDispatchActionTypeCode() != null && reqDto.getDispatchActionTypeCode().equals("DISPATCH_ADD_REPORT_TASK"))) {
            //if(B3提交人工补偿异步调度任务(管理).任务调度的行为类型编码 等于 调度生成汇报任务)  7059

            GenerateTargetReportTasksComRespDto generateTargetReportTasksComRespDto = null;
            GenerateTargetReportTasksComReqDto generateTargetReportTasksComReqDto = new GenerateTargetReportTasksComReqDto();
            if (reqDto != null) {
                generateTargetReportTasksComReqDto.setTimingTaskDispatchId(reqDto.getTimingTaskDispatchId());//SimpleFieldAssign//sourceId:356769_1_7060
                generateTargetReportTasksComReqDto.setEvaObjTargetCycleId(reqDto.getObjectId());//SimpleFieldAssign//sourceId:127375_1_7060
                generateTargetReportTasksComReqDto.setExecuteCycleStageId(reqDto.getAddRuleInfoId());//SimpleFieldAssign//sourceId:680506_1_7060
                generateTargetReportTasksComReqDto.setCompareTime(reqDto.getAutoPlanTime());//SimpleFieldAssign//sourceId:127379_1_7060
                generateTargetReportTasksComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:127376_1_7060
            }

            /*D3生成目标内容汇报任务(公共)[3293]   */
            Assert.isNull(generateTargetReportTasksComReqDto.getTimingTaskDispatchId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3生成目标内容汇报任务(公共)-定时任务调度记录ID不能为空", false);
            Assert.isNull(generateTargetReportTasksComReqDto.getEvaObjTargetCycleId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3生成目标内容汇报任务(公共)-被评对象目标周期ID不能为空", false);
            Assert.isNull(generateTargetReportTasksComReqDto.getExecuteCycleStageId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3生成目标内容汇报任务(公共)-执行周期阶段ID不能为空", false);
            Assert.isNull(generateTargetReportTasksComReqDto.getCompareTime(), "B3提交人工补偿异步调度任务(管理)(平台)-D3生成目标内容汇报任务(公共)-比较时间不能为空", false);
            Assert.isNull(generateTargetReportTasksComReqDto.getSpaceId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3生成目标内容汇报任务(公共)-创建于空间ID不能为空", false);
            generateTargetReportTasksComRespDto = fwAppTaskClient.generateTargetReportTasksCom(generateTargetReportTasksComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


//processBranchName:正常结束 ,processBranchId:7065

        } else if ((reqDto != null && reqDto.getDispatchActionTypeCode() != null && reqDto.getDispatchActionTypeCode().equals("STAGE_CURRENT_CYCLE_ETC"))) {
            //elseif(B3提交人工补偿异步调度任务(管理).任务调度的行为类型编码 等于 调度更新周期阶段当前周期等)  7603

            RefreshAllTempDeviationDaysAndCurrentCycleComRespDto refreshAllTempDeviationDaysAndCurrentCycleComRespDto = null;
            RefreshAllTempDeviationDaysAndCurrentCycleComReqDto refreshAllTempDeviationDaysAndCurrentCycleComReqDto = new RefreshAllTempDeviationDaysAndCurrentCycleComReqDto();
            if (reqDto != null) {
                refreshAllTempDeviationDaysAndCurrentCycleComReqDto.setTimingTaskDispatchId(reqDto.getTimingTaskDispatchId());//SimpleFieldAssign//sourceId:1780421_1_68070
                refreshAllTempDeviationDaysAndCurrentCycleComReqDto.setTargetCycleContentId(reqDto.getObjectId());//SimpleFieldAssign//sourceId:1780425_1_68070
                refreshAllTempDeviationDaysAndCurrentCycleComReqDto.setEvaluationTemplateId(reqDto.getAddRuleInfoId());//SimpleFieldAssign//sourceId:1780423_1_68070
                refreshAllTempDeviationDaysAndCurrentCycleComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1780424_1_68070
            }

            /*D3更新全评价模板目标周期偏差天数及当前执行周期(公共)[9509]   */
            Assert.isNull(refreshAllTempDeviationDaysAndCurrentCycleComReqDto.getTimingTaskDispatchId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3更新全评价模板目标周期偏差天数及当前执行周期(公共)-定时任务调度记录ID不能为空", false);
            Assert.isNull(refreshAllTempDeviationDaysAndCurrentCycleComReqDto.getTargetCycleContentId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3更新全评价模板目标周期偏差天数及当前执行周期(公共)-关联目标内容ID不能为空", false);
            Assert.isNull(refreshAllTempDeviationDaysAndCurrentCycleComReqDto.getEvaluationTemplateId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3更新全评价模板目标周期偏差天数及当前执行周期(公共)-冗余评价模板ID不能为空", false);
            Assert.isNull(refreshAllTempDeviationDaysAndCurrentCycleComReqDto.getSpaceId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3更新全评价模板目标周期偏差天数及当前执行周期(公共)-创建于空间ID不能为空", false);
            refreshAllTempDeviationDaysAndCurrentCycleComRespDto = fwAppTimingTaskClient.refreshAllTempDeviationDaysAndCurrentCycleCom(refreshAllTempDeviationDaysAndCurrentCycleComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


//processBranchName:正常结束 ,processBranchId:7605

        } else if ((reqDto != null && reqDto.getDispatchActionTypeCode() != null && reqDto.getDispatchActionTypeCode().equals("TASK_OVERDUE_ETC"))) {
            //elseif(B3提交人工补偿异步调度任务(管理).任务调度的行为类型编码 等于 调度更新任务逾期等数据)  7608

            RefreshTaskOverdueEtcComRespDto refreshTaskOverdueEtcComRespDto = null;
            RefreshTaskOverdueEtcComReqDto refreshTaskOverdueEtcComReqDto = new RefreshTaskOverdueEtcComReqDto();
            if (reqDto != null) {
                refreshTaskOverdueEtcComReqDto.setTaskId(reqDto.getObjectId());//SimpleFieldAssign//sourceId:135895_1_7609
                refreshTaskOverdueEtcComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:135896_1_7609
            }

            /*D3-3更新汇报任务状态相关(公共)[3359]   */
            Assert.isNull(refreshTaskOverdueEtcComReqDto.getTaskId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3-3更新汇报任务状态相关(公共)-任务ID不能为空", false);
            Assert.isNull(refreshTaskOverdueEtcComReqDto.getSpaceId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3-3更新汇报任务状态相关(公共)-创建于空间ID不能为空", false);
            refreshTaskOverdueEtcComRespDto = fwAppTimingTaskClient.refreshTaskOverdueEtcCom(refreshTaskOverdueEtcComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


//processBranchName:正常结束 ,processBranchId:7610

        } else if ((reqDto != null && reqDto.getDispatchActionTypeCode() != null && reqDto.getDispatchActionTypeCode().equals("DISATCH_TARGET_ANCESTOR_TASK"))) {
            //elseif(B3提交人工补偿异步调度任务(管理).任务调度的行为类型编码 等于 调度生成设定祖先目标父子状态调度任务)  8530

            LoopSetAncestorParentStateComRespDto loopSetAncestorParentStateComRespDto = null;
            LoopSetAncestorParentStateComReqDto loopSetAncestorParentStateComReqDto = new LoopSetAncestorParentStateComReqDto();
            if (reqDto != null) {
                loopSetAncestorParentStateComReqDto.setAssistNodeTypeObjectId(reqDto.getObjectId());//SimpleFieldAssign//sourceId:145093_1_8531
                loopSetAncestorParentStateComReqDto.setTimingTaskDispatchId(reqDto.getTimingTaskDispatchId());//SimpleFieldAssign//sourceId:142166_1_8531
                loopSetAncestorParentStateComReqDto.setAssistNodeTypeObjectCode(reqDto.getStandbyField1());//SimpleFieldAssign//sourceId:362889_1_8531
                loopSetAncestorParentStateComReqDto.setAssistNodeTypeCode(reqDto.getObjectTypeCode());//SimpleFieldAssign//sourceId:362890_1_8531
                loopSetAncestorParentStateComReqDto.setObjectTypeCode(reqDto.getAddRuleInfoTypeCode());//SimpleFieldAssign//sourceId:368400_1_8531
                loopSetAncestorParentStateComReqDto.setObjectId(reqDto.getAddRuleInfoId());//SimpleFieldAssign//sourceId:362887_1_8531
            }

            /*D3-11循环设定祖先父子状态(公共)[3445]   */
            Assert.isNull(loopSetAncestorParentStateComReqDto.getAssistNodeTypeObjectId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3-11循环设定祖先父子状态(公共)-当前本级目标内容ID不能为空", false);
            Assert.isNull(loopSetAncestorParentStateComReqDto.getTimingTaskDispatchId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3-11循环设定祖先父子状态(公共)-定时任务调度记录ID不能为空", false);
            Assert.isNull(loopSetAncestorParentStateComReqDto.getAssistNodeTypeObjectCode(), "B3提交人工补偿异步调度任务(管理)(平台)-D3-11循环设定祖先父子状态(公共)-当前本级目标内容标识不能为空", false);
            Assert.isNull(loopSetAncestorParentStateComReqDto.getAssistNodeTypeCode(), "B3提交人工补偿异步调度任务(管理)(平台)-D3-11循环设定祖先父子状态(公共)-当前本级目标内容类型编码不能为空", false);
            Assert.isNull(loopSetAncestorParentStateComReqDto.getObjectTypeCode(), "B3提交人工补偿异步调度任务(管理)(平台)-D3-11循环设定祖先父子状态(公共)-归属对象类型编码不能为空", false);
            Assert.isNull(loopSetAncestorParentStateComReqDto.getObjectId(), "B3提交人工补偿异步调度任务(管理)(平台)-D3-11循环设定祖先父子状态(公共)-评价模版ID不能为空", false);
            loopSetAncestorParentStateComRespDto = fwAppTimingTaskClient.loopSetAncestorParentStateCom(loopSetAncestorParentStateComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


//processBranchName:正常结束 ,processBranchId:8532

        }
        BffCommitHandRescueSlowTaskRespDto retData = new BffCommitHandRescueSlowTaskRespDto();


        return retData;
    }

    /**
     * B3执行启用租户空间长生调度MQ(管理)[6822]
     * gen by moon at 5/18/2023, 11:08:37 PM
     */
    @Trace(operationName = "B3执行启用租户空间长生调度MQ(管理)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffImplementEnableSpaceEverYoungDispatchMqRespDto implementEnableSpaceEverYoungDispatchMq(BffImplementEnableSpaceEverYoungDispatchMqReqDto reqDto) {


        //步骤0: D3执行启用空间长生调度MQ(公共) - implementEnableSpaceEverYoungDispatchMqCom
        ImplementEnableSpaceEverYoungDispatchMqComRespDto implementEnableSpaceEverYoungDispatchMqComRespDto = null;
        ImplementEnableSpaceEverYoungDispatchMqComReqDto implementEnableSpaceEverYoungDispatchMqComReqDto = new ImplementEnableSpaceEverYoungDispatchMqComReqDto();
        if (reqDto != null) {
            implementEnableSpaceEverYoungDispatchMqComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:957228_1
        }

        /*D3执行启用空间长生调度MQ(公共)[5092]   */
        Assert.isNull(implementEnableSpaceEverYoungDispatchMqComReqDto.getSpaceId(), "B3执行启用租户空间长生调度MQ(管理)-D3执行启用空间长生调度MQ(公共)-空间ID不能为空", false);
        implementEnableSpaceEverYoungDispatchMqComRespDto = fwAppTimingTaskClient.implementEnableSpaceEverYoungDispatchMqCom(implementEnableSpaceEverYoungDispatchMqComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


        BffImplementEnableSpaceEverYoungDispatchMqRespDto retData = new BffImplementEnableSpaceEverYoungDispatchMqRespDto();


        return retData;
    }

    /**
     * B3执行分析狗骨头剩余情况(管理)[6825]
     * gen by moon at 5/18/2023, 11:08:44 PM
     */
    @Trace(operationName = "B3执行分析狗骨头剩余情况(管理)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffImplementAnalyseDogBoneResidueRespDto implementAnalyseDogBoneResidue(BffImplementAnalyseDogBoneResidueReqDto reqDto) {


        ImplementAnalyseDogBoneResidueRespDto implementAnalyseDogBoneResidueRespDto_1 = null;
//步骤0: D3执行分析狗骨头剩余情况 - implementAnalyseDogBoneResidue
        ImplementAnalyseDogBoneResidueRespDto implementAnalyseDogBoneResidueRespDto = null;
        ImplementAnalyseDogBoneResidueReqDto implementAnalyseDogBoneResidueReqDto = new ImplementAnalyseDogBoneResidueReqDto();
        if (reqDto != null) {
            implementAnalyseDogBoneResidueReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:958002_1
        }

        /*D3执行分析狗骨头剩余情况[6823]   */
        Assert.isNull(implementAnalyseDogBoneResidueReqDto.getSpaceId(), "B3执行分析狗骨头剩余情况(管理)-D3执行分析狗骨头剩余情况-空间ID不能为空", false);
        implementAnalyseDogBoneResidueRespDto = fwAppTimingTaskClient.implementAnalyseDogBoneResidue(implementAnalyseDogBoneResidueReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


        implementAnalyseDogBoneResidueRespDto_1 = implementAnalyseDogBoneResidueRespDto;

        BffImplementAnalyseDogBoneResidueRespDto retData = new BffImplementAnalyseDogBoneResidueRespDto();
        if (implementAnalyseDogBoneResidueRespDto_1 != null) {
            retData.setUnfinishedNum(implementAnalyseDogBoneResidueRespDto_1.getUnfinishedNum());//SimpleFieldAssign//sourceId:958005_1
        }


        return retData;
    }
    //
}
